/*
 * Copyright 2009-2010 Nanjing RedOrange ltd (http://www.red-orange.cn)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package redora.api;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Set;

/**
 * The [modelName]Base classes implement this interface.
 *
 * @author Nanjing RedOrange (http://www.red-orange.cn)
 */
public interface Persistable extends Cloneable {
    /**
     * @return Database generated primary key.
     */
    Long getId();

    /**
     * True when any attribute has changed. Changes in related children are not
     * detected. In that case use the PojoService.hasChanged method.
     * @param ignore (Optional) Ignores children / parents already in the list
     * @return True if there is something to persist
     */
    boolean isDirty(@Nullable Set<Persistable> ignore);

    /**
     * Quite a good clone. The Persistable is cloned, related collections are cloned.
     * First level objects are also cloned.
     * Id, creationDate and updateDate are nor cloned. So !clone.equals(original)
     * @param depth This is a recursive method, the depth will limit recursions to MAX_DIRTY_LEVEL
     * @return The clone
     */
    @NotNull
    Persistable clone(int depth);
}
